<?php

#################################################################
#								HTML
#################################################################

/**
 * Login panel at header component register as 'component/header_login' 
 * 
 */

if($_CONTEXT=='HTML'){
	
	$_CSS_STACK->push(blg_get_site_url().'component/header_login.css', TRUE);
	//$_JS_STACK->push(blg_get_site_url().'component/header_login.js', TRUE);		
	
	$user_logged= blg_get_logged_in_user_guid();
	
	if($user_logged!==FALSE){		
		$user= blg_get_user_entity($user_logged);
		$is_admin= ($user->admin=='yes');
	}
	else{
		$user= FALSE;
		$is_admin= FALSE;		
	}

	/***************************************************
	 * 					NOT LOGGED IN
	 ***************************************************/	
	if($user_logged===FALSE){
		
		$button= blg_view('element/button', array(
			'text' => blg_echo('login'),	
			'action' => "blg_header_login_show();",
			'id' => 'header_input_login_button'	
		));
		
		$options= array();
		if(blg_session_isset('show_login_form')){
			$value= blg_session_get('show_login_form');
			$options= array(
				'email' => $value['email'],
				'pass' 	=> $value['pass'],
				'display_login_form' => TRUE
			);
		}		
		$login_div= blg_view('form/login', $options);		
		
		$options= array();
		if(blg_session_isset('form_register_failed')){
			$value= blg_session_get('form_register_failed');
			$options= array(
				'name' 		=> $value['name'],
				'username' 	=> $value['username'],
				'email' 	=> $value['email'],
				'pass1' 	=> $value['pass1'],
				'pass2' 	=> $value['pass2'],
				'display_register_form' => TRUE
			);			
		}			
		$register_div= blg_view('form/register', $options);
		
		$welcome= '- '.blg_echo('welcome').' -';
		$action_txt= blg_echo('register');
		$action_url= 'javascript:blg_form_register_show();';
	}
	/***************************************************
	 * 				  USER LOGGED IN
	 ***************************************************/	
	else{
		$button= blg_view('element/button', array(
			'text' => blg_echo('logout'),	
			'url' => blg_get_site_url()."action/user/logout",
			'id' => 'header_input_login_button'	
		));
		
		$welcome= '- '.($user->name).' -';
		$action_txt= blg_echo('user:my_profile');
		$action_url= blg_get_site_url().'user/profile?'.$user->code;		
	}
	

echo <<<HTML
$login_div
$register_div
<div class="blg_component_header_login">
	<div class="blg_component_header_login_welcome">$welcome</div>
	<div class="blg_component_header_login_button">$button</div>
	<div class="blg_component_header_login_register"><a class="white_underline" href="$action_url">$action_txt</a></div>
</div>
HTML;
}
#################################################################
#								JS
#################################################################
elseif($_CONTEXT=='JS'){ ?>

<?php }
#################################################################
#								CSS
#################################################################
elseif($_CONTEXT=='CSS'){ ?>

div.blg_component_header_login{
	float: right;
	height: 74px;
	color: <?php echo blg_color('white','white')?>;
	width: 150px;
	text-align: center;
		
	border: 0px solid green;
}

div.blg_component_header_login div.blg_component_header_login_welcome,
div.blg_component_header_login div.blg_component_header_login_button,
div.blg_component_header_login div.blg_component_header_login_register{
	height: 25px;
	line-height: 25px;
}

div.blg_component_header_login div.blg_component_header_login_welcome{
	font-size: 12px;
	color: <?php echo blg_color('grey','9')?>;
}

div.blg_component_header_login div.blg_component_header_login_button{
}

div.blg_component_header_login div.blg_component_header_login_register{
	font-size: 12px;
}


<?php }
